{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##  知识点总结"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# if语句"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Study！\n"
     ]
    }
   ],
   "source": [
    "# if xxxxx :\n",
    "# elif xxxxx:\n",
    "# else:\n",
    "\n",
    "if 'today' == 'Saturday':\n",
    "    print('Party!')\n",
    "elif 'today' == 'Sunday':\n",
    "    if condition == 'Headache':\n",
    "        print('Recover, then rest.')\n",
    "    else:\n",
    "        print('Rest.')\n",
    "else:\n",
    "    print('Study！')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# for循环以及range内置函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "# for循环\n",
    "\n",
    "a=[1,2,3]\n",
    "for b in a:\n",
    "    print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n\n",
      "e\n",
      "o\n"
     ]
    }
   ],
   "source": [
    "for a in 'neo':\n",
    "    print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "neo culture technology\n",
      "neo culture technology\n",
      "neo culture technology\n",
      "neo culture technology\n",
      "neo culture technology\n"
     ]
    }
   ],
   "source": [
    "# range 循环\n",
    "\n",
    "for num in range(5):\n",
    "    print('neo culture technology')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# random函数学习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 生成随机整数\n",
    "\n",
    "import random\n",
    "random.randint(1, 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.933986051227149\n"
     ]
    }
   ],
   "source": [
    "#生成一个大于0小于1的随机数\n",
    "\n",
    "import random\n",
    "a=random.random()\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n"
     ]
    }
   ],
   "source": [
    "# 从指定范围内，按指定的基数递增的集合中获取一个随机数\n",
    "\n",
    "import random\n",
    "a=random.randrange(0,20,4)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 字符串的拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'neoculture'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 拼接\n",
    "'neo'+'culture'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "neo culture\n"
     ]
    }
   ],
   "source": [
    "print('neo','culture')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "neo culture\n"
     ]
    }
   ],
   "source": [
    "print('%s %s'%('neo','culture'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Neo culture technology\n"
     ]
    }
   ],
   "source": [
    "a='Neo culture technology'\n",
    "b=''.join(a)\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Neo', 'culture', 'technology']\n"
     ]
    }
   ],
   "source": [
    "# 拆分\n",
    "a='Neo,culture,technology'\n",
    "b=a.split(',')\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "# 计算字符串某个数值出现的次数\n",
    "a='1,2,1,3,1,'\n",
    "print(a.count('1'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 列表\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "函数\n",
    "\n",
    "|函数|解释|  \n",
    "|---|:--:|  \n",
    "|cmp(list1,list2)|比较两个列表的元素|  \n",
    "|len(list)|列表元素个数|  \n",
    "|max(list)|返回列表元素最大值|  \n",
    "|min(list)|返回列表元素最小值|  \n",
    "|list(seq)|将元组转换为列表|  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "方法\n",
    "\n",
    "|方法|解释|\n",
    "|---|:--:|\n",
    "|list.append(obj)|在列表末尾添加新的对象|\n",
    "|list.count(obj)|统计某个元素在列表中出现的次数|\n",
    "|list.extend(seq)|在列表末尾一次性追加另一个序列中的多个值（用新列表扩展原来的列表）|\n",
    "|list.index(obj)|从列表中找出某个值第一个匹配项的索引位置|\n",
    "|list.insert(index,obj)|将对象插入列表|\n",
    "|list.pop(index=-1)|移除列表中的一个元素（默认最后一个元素），并且返回该元素的值|\n",
    "|list.remove(obj)|移除列表中某个值的第一个匹配像|\n",
    "|list.reverse()|反向列表中元素|   |list.sort(cmp=None,key=None,reverse=False)|对原列表进行排序|\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['1', '2', '3']"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#list.append(obj)\t在列表末尾添加新的对象\n",
    "a=['1','2']\n",
    "a.append('3')\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#list.count(obj)\t统计某个元素在列表中出现的次数\n",
    "a=[1,2,3]\n",
    "a.count(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['1', '2', '3']"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#list.extend(seq)\t在列表末尾一次性追加另一个序列中的多个值（用新列表扩展原来的列表）\n",
    "a=['1']\n",
    "a.extend('23')\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#list.index(obj)\t从列表中找出某个值第一个匹配项的索引位置\n",
    "a=[1,2,3]\n",
    "a.index(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#list.insert(index,obj)\t将对象插入列表\n",
    "a=[2,3]\n",
    "a.insert(0,1)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#list.pop(index=-1)\t移除列表中的一个元素（默认最后一个元素），并且返回该元素的值\n",
    "a=[1,2,3]\n",
    "a.pop(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 3]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#list.remove(obj)\t移除列表中某个值的第一个匹配像\n",
    "a=[1,2,3]\n",
    "a.remove(1)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[3, 2, 1]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#list.reverse()\t反向列表中元素\n",
    "a=[1,2,3]\n",
    "a.reverse()\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 元组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'tuple'>\n",
      "1\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "# 元组只有两个方法，count和index\n",
    "a = (3,2,1,4,5,2,2,4,5,6,4)\n",
    "print(type(a))\n",
    "print(a.index(2))\n",
    "print(a.count(2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the count is: 0\n",
      "the count is: 1\n",
      "the count is: 2\n",
      "the count is: 3\n",
      "the count is: 4\n",
      "bye\n"
     ]
    }
   ],
   "source": [
    "# while循环\n",
    "count = 0 \n",
    "while (count<5):\n",
    "    print( 'the count is:',count)\n",
    "    count =count +1\n",
    "    \n",
    "print(\"bye\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "4\n",
      "6\n",
      "8\n",
      "10\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "#continue用于跳过该次循环\n",
    "#break用于退出循环\n",
    "i = 1\n",
    "while i <10:\n",
    "    i += 1\n",
    "    if i%2>0: \n",
    "        continue\n",
    "    print(i)\n",
    "\n",
    "i = 1\n",
    "while 1:\n",
    "    print(i)\n",
    "    i +=1\n",
    "    if i>10:\n",
    "        break"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 字典"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': 'zjy', 'gender': 'female', 'age': '20'}\n"
     ]
    }
   ],
   "source": [
    "#创建字典\n",
    "info = {\n",
    "    \"name\": \"zjy\",\n",
    "    \"gender\": \"female\",\n",
    "    \"age\": \"20\"\n",
    "}\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': 'zjy', 'gender': 'female', 'age': '20', 'class': '02'}\n"
     ]
    }
   ],
   "source": [
    "#字典的增加\n",
    "info[\"class\"] = \"02\"\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': 'zjy', 'gender': 'female', 'age': '20', 'class': '01'}\n"
     ]
    }
   ],
   "source": [
    "#字典的修改\n",
    "info[\"class\"] = \"01\"\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': 'zjy', 'gender': 'female', 'age': '20'}\n",
      "{'name': 'zjy', 'gender': 'female', 'age': '20'}\n",
      "{'name': 'zjy', 'gender': 'female'}\n"
     ]
    }
   ],
   "source": [
    "#字典的删除\n",
    "\n",
    "#标准删除\n",
    "info.pop(\"class\")\n",
    "print(info)\n",
    "\n",
    "#删除“name”\n",
    "del info[\"name\"]\n",
    "\n",
    "# 随机删除\n",
    "info = {\"name\":\"zjy\",\"gender\":\"female\",\"age\":\"20\"}\n",
    "print(info)\n",
    "info.popitem()\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 字典的嵌套"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Arthur': {'Gender': 'Male',\n",
      "            'Home Planet': 'Earth',\n",
      "            'Name': 'Arthur Dent',\n",
      "            'Occupation': 'Sandwich-Maker'},\n",
      " 'Ford': {'Gender': 'Male',\n",
      "          'Home Planet': 'Betelgeuse Seven',\n",
      "          'Name': 'Ford Prefect',\n",
      "          'Occupation': 'Researcher'},\n",
      " 'Marvin': {'Gender': 'Unknown',\n",
      "            'Home Planet': 'Unknown',\n",
      "            'Name': 'Marvin',\n",
      "            'Occupation': 'Paranoid Android'},\n",
      " 'Tricia': {'Gender': 'Female',\n",
      "            'Home Planet': 'Earth',\n",
      "            'Name': 'Tricia McMillan',\n",
      "            'Occupation': 'Mathematician'}}\n"
     ]
    }
   ],
   "source": [
    "import pprint  \n",
    "people = {}\n",
    "people['Ford'] = {\"Name\":'Ford Prefect',\n",
    "                  \"Gender\":'Male',\n",
    "                  \"Occupation\":'Researcher',\n",
    "                  \"Home Planet\":'Betelgeuse Seven'}\n",
    "people['Arthur'] = {\"Name\":'Arthur Dent',\n",
    "                  \"Gender\":'Male',\n",
    "                  \"Occupation\":'Sandwich-Maker',\n",
    "                  \"Home Planet\":'Earth'}\n",
    "people['Tricia'] = {\"Name\":'Tricia McMillan',\n",
    "                    \"Gender\":'Female',\n",
    "                    \"Occupation\":'Mathematician',\n",
    "                    \"Home Planet\":'Earth'}\n",
    "people['Marvin'] = {\"Name\":'Marvin',\n",
    "                    \"Gender\":'Unknown',\n",
    "                    \"Occupation\":'Paranoid Android',\n",
    "                    \"Home Planet\":'Unknown'}\n",
    "pprint.pprint(people)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 字典的内置函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算字典元素个数，即键的总数\n",
    "dict = {'Name': 'zjy', 'Age': 20, 'Class': '01'}\n",
    "len(dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 输出字典可打印的字符串表示\n",
    "dict = {'Name': 'zjy', 'Age': 20, 'Class': '01'}\n",
    "str(dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#返回输入的变量类型，如果变量是字典就返回字典类型\n",
    "dict = {'Name': 'zjy', 'Age': 20, 'Class': '01'}\n",
    "type(dict)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "方法\n",
    "\n",
    "| 函数      |      描述  |\n",
    "|:----------|:-----------|\n",
    "|dict.clear()|删除字典内所有元素|\n",
    "|dict.copy()|返回一个字典的浅复制|\n",
    "|dict.formkeys.(seq,[val])|创建一个新字典，以序列seq中元素做字典的键，val为字典所有键对应的初始值|\n",
    "|dict.get(key,default=None)|返回指定键的值，如果值不在字典中返回default值|\n",
    "|dict.has_key(kay)|如果键在字典里返回true，否则返回false|\n",
    "|dict.items()|以列表返回可遍历的（键，值）元组数组|\n",
    "|dict.keys()|以列表返回一个字典所有的键|\n",
    "|dict.setdefault(key,default=None)|和get()类似，但如果键不存在于字典中，将会添加键并将值设为default|\n",
    "|dict.update(dict2)|把字典dict2的键/值对更新到dict里|\n",
    "|dict.values()|以列表返回字典中的所有值|\n",
    "|pop(key,[default])|删除字典给定键key所对应的值，返回值为被删除的值，key值必须给出，否则，返回default值|\n",
    "|pop.item()|返回并删除字典中的最后一对键和值|"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 集合"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "方法\n",
    "\n",
    "|方法      |      描述  |\n",
    "|:----------|:-----------|\n",
    "|add()|为集合添加元素|\n",
    "|clear()|移除集合中的所有元素|\n",
    "|copy()|拷贝一个集合|\n",
    "|difference()|返回多个集合的差集|\n",
    "|difference_update()|移除集合中的元素，该元素在指定的集合也存在|\n",
    "|discard()|删除集合中指定的元素|\n",
    "|intersection()|返回集合的交集|\n",
    "|intersection_updata()|返回集合的交集|\n",
    "|isdisjoint()|判断两个集合是否包含相同的元素，如果没有返回true，否则返回false|\n",
    "|issubset()|判断指定集合是否为该方法参数集合的子集|\n",
    "|issuperset()|判断该方法的参数集合是否为指定集合的子集|\n",
    "|pop()|随机移除元素|\n",
    "|remove()|移除指定元素|\n",
    "|symmetric_difference()|返回两个集合中不重复的元素集合|\n",
    "|symmetric_difference_update()|移除当前集合中在另外一个指定集合相同的元素，并将另外一个指定集合中不同的元素插入到当前集合中|\n",
    "|union()|返回两个集合的并集|\n",
    "|update()|给集合添加元素|"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "131.458px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
